#zonal harmonic
def Znt(x,n,t):
return (2*t+n-2)/(n-2)*gegenbauer(t,(n-2)/2,x)
def K4bound(v,k,l,m,t): #l=lambda m=mu
#auxiliary variables
aux_root = sqrt((l-m)^2+4*(k-m))
aux_quot = (2*k+(v-1)*(l-m))/aux_root
#positive eigenvalue with multiplicity
r = (l-m+aux_root)/2
f = (v-1-aux_quot)/2
#negative eigenvalue with multiplicity
s = (l-m-aux_root)/2
g = (v-1+aux_quot)/2
#inner products in R^g
p = s/k
q = -(s+1)/(v-k-1)
#Psi_A from (3.3)
Psi_A = v*(Znt(1,g,t)+k*Znt(p,g,t)+(v-k-1)*Znt(q,g,t))
#Psi_B from (3.4)
dn = sqrt(2+2*p) #denominators
Psi_B = v*k*Znt((1+p)/dn,g,t)+v*k*l/2*Znt(2*p/dn,g,t)+v*(v-k-1)*m*Znt((p+q)/dn,g,t)+v*(v-k-1)*(k-m)/2*Znt(2*q/dn,g,t)
#Psi_C_0 from (3.6)
dn = 2+2*p #denominators
Psi_C_0 = v*k/2*(Znt(1,g,t)+2*l*Znt((1+3*p)/dn,g,t)+2*(k-l-1)*Znt((1+2*p+q)/dn,g,t)+2*l*(l-1)*Znt((3*p+q)/dn,g,t)+((m-1)*(k-l-1)-l*(l-1)+2*l*(k-2*l))*Znt((2*p+2*q)/dn,g,t)+2*((k-m)*(k-l-1)-l*(k-2*l))*Znt((p+3*q)/dn,g,t)+(k*(v-2*k+l)/2-(k-m)*(k-l-1)+l*(k-2*l)/2)*Znt((4*q)/dn,g,t))
#Psi_C_1 from (3.7) with j as summation index
Psi_C_1 = 0
for j in range(5):
Psi_C_1 += 6*(-1)^j*binomial(4,j)*Znt(((4-j)*p+j*q)/dn,g,t)
if Psi_A*Psi_C_1<=0:
return 0
else:
return ceil(((Psi_B^2/Psi_A-Psi_C_0)/Psi_C_1).n())